// copyright jyz.2024

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AbilitySystemInterface.h"
#include "Interaction/CombatInterface.h"
#include "AuraCharacterBase.generated.h"
class UGameplayEffect;
class UAbilitySystemComponent;
class USkeletalMeshComponent;
class UAttributeSet;
class UGameplayAbility;
class UMotionWarpingComponent;
UCLASS(Abstract)
class AURARPGDEMO_API AAuraCharacterBase : public ACharacter,public IAbilitySystemInterface,public ICombatInterface
{
	GENERATED_BODY()

public:
	AAuraCharacterBase();
	virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
	UAttributeSet* GetAttributeSet()const {return AttributeSet;}
protected:
	virtual void BeginPlay() override;

	/** Begine CombaInterface */
	UPROPERTY(EditDefaultsOnly,Category="Combat")
	FName WarpTargetName;
	virtual void SetFacingTarget(FVector FacingTargetLocation) override;
	virtual UAnimMontage* GetHitReactAnimMontage() const override;
	virtual void Die() override;

	UFUNCTION(NetMulticast,Reliable)
	virtual void MulticastHandleDeath();
protected:
	UPROPERTY(EditDefaultsOnly)
	TObjectPtr<UAnimMontage> HitReact;
	/** End CombaInterface */

	//死亡溶解
	void Dissolve();
	UFUNCTION(BlueprintImplementableEvent)
	void Death();
	UFUNCTION(BlueprintImplementableEvent)
	void StartDissolveTimeline(UMaterialInstanceDynamic* DynamicMat);
	UFUNCTION(BlueprintImplementableEvent)
	void StartWeaponDissolveTimeline(UMaterialInstanceDynamic* DynamicMat);
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	TObjectPtr<UMaterialInstance> DissolveMaterialInstance;
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	TObjectPtr<UMaterialInstance> WeaponDissolveMaterialInstance;
	virtual void InitAbilityActorInfo();
	virtual void InitializeDefaultAttribute();
	/**
	 * 给角色添加能力
	 */
	void AddGameAbilities();
protected:
	//Note:Combat==战斗
	UPROPERTY(EditAnywhere,Category="Combat")
	TObjectPtr<USkeletalMeshComponent> Weapon;
	UPROPERTY(EditAnywhere,Category="Combat")
	TObjectPtr<UMotionWarpingComponent> MotionWarping;
	UPROPERTY(EditAnywhere,Category="Combat")
	FName WeaponTipSocketName;
	virtual FVector GetCombatSocketLocation() override;
	UPROPERTY()
	TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;
	UPROPERTY()
	TObjectPtr<UAttributeSet> AttributeSet;

	UPROPERTY(EditAnywhere,BlueprintReadOnly,Category="Attributes")
	TSubclassOf<UGameplayEffect> DefaultPrimaryAttributes;
	UPROPERTY(EditAnywhere,BlueprintReadOnly,Category="Attributes")
	TSubclassOf<UGameplayEffect> DefaultSecondaryAttributes;
	UPROPERTY(EditAnywhere,BlueprintReadOnly,Category="Attributes")
	TSubclassOf<UGameplayEffect> DefaultVitalAttributes;
private:
	void InitAttributeValues(TSubclassOf<UGameplayEffect> DefaultAttributes,float Level) const;
	
	UPROPERTY(EditAnywhere,Category="Abilities")
	TArray<TSubclassOf<UGameplayAbility>> StartupAbilities;
};
